package com.bnlr.lrparking.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bnlr.lrparking.R;
import com.yolanda.nohttp.rest.Request;

/**
 * Created by rr on 2016/7/2.
 * 选择搜索类型
 */
public class SeachTypeAdapter extends BaseAdapter {

    public Request<String> mRequest;
    private Context mcontext;
    private String [] mstr;
    private LayoutInflater inflater;
    private int defaultSelection = 0;


    public SeachTypeAdapter(Context context, String [] str) {
        super();
        this.mcontext = context;
        this.mstr = str;
        inflater = LayoutInflater.from(mcontext);
    }

    @Override
    public int getCount() {
        if (mstr != null) {
            return mstr.length;
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        final ViewHoder hoder;
        if (convertView == null) {
            hoder = new ViewHoder();
            convertView = inflater.inflate(R.layout.item_seanchtype, null);
            hoder.item_name = (TextView) convertView.findViewById(R.id.tv_seachtype);
            convertView.setTag(hoder);
        } else {
            hoder = (ViewHoder) convertView.getTag();
        }
        hoder.item_name.setText(mstr[i]);
        if (i == defaultSelection) {// 选中时设置单纯颜色
            hoder.item_name.setBackgroundResource(R.mipmap.type_bg2);
            hoder.item_name.setTextColor(0xffffffff);
        } else {// 未选中时设置selector
            hoder.item_name.setBackgroundResource(R.mipmap.type_bg1);
            hoder.item_name.setTextColor(0xff666666);
        }
        return convertView;
    }

    class ViewHoder {
        TextView item_name;
    }

    public void setSelectPosition(int i) {
        if (!(i < 0 || i > mstr.length)) {
            defaultSelection = i;
            notifyDataSetChanged();
        }
    }
}
